pacman::p_load(olsrr, corrplot, ggpubr, sf, spdep, GWmodel, tmap, tidyverse, gtsummary)Take Home Exercise 3: Calibrating Hedonic Pricing Model for Airbnb Housing with GWR Method
Take Home Assignment 3
We will be performing Geographically weighted regression (GWR) to derive estimates for airnb housing based on their other properties such as reviews per month. This will then be displayed on the shiny app for users to play around and get help in finding estimates so that they can choose which airbnb housings will suit their needs best. Geographically weighted regression (GWR) is a spatial statistical technique that takes non-stationary variables into consideration (e.g., climate; demographic factors; physical environment characteristics) and models the local relationships between these independent variables and an outcome of interest (also known as dependent variable). In this hands-on exercise, you will learn how to build hedonic pricing models for airbnb flats in Singapore by using GWR methods. The dependent variable is the airbnb prices of flats over several years. The independent variables are divided into either numerical and locational.
After all the outputs and analysis has been done as shown below, the shiny app will be displayed as follows for users to interact with:
UI Prototype


The design of the app will allow users to seamlessly select between the 3 main models, namely simple, multiple and GWModel. Users will be able to generate the charts to see how explainable the model is with the R2 map. Alternatively they will also be able to choose the coefficient map to see how much the variables affect each region’s estimates. For the three models they will be able to select from the relevant parameters to generate the plots.
Below these maps, there will be a table used to present the various publication quality reports for more detail inclined individuals to see for themselves the exact values and quality of the model such as with the use of sum of squares that indicates how much the prediction varies from actual values.
The Data
Two data sets will be used in this model building exercise, they are:
URA Master Plan subzone boundary in shapefile format (i.e. MP14_SUBZONE_WEB_PL)
airbnb prices in csv format (i.e. listings.csv)
Getting Started
Before we get started, it is important for us to install the necessary R packages into R and launch these R packages into R environment.
The R packages needed for this exercise are as follows:
R package for building OLS and performing diagnostics tests
R package for calibrating geographical weighted family of models
R package for multivariate data visualisation and analysis
Spatial data handling
- sf
Attribute data handling
- tidyverse, especially readr, ggplot2 and dplyr
Choropleth mapping
- tmap
Ggplotly will also be used for 3D possible visualisations for a more interactive user experience. It is seen as relatively more mature package due to its ease of use in being able to download images from the interface itself, being able to zoom into details with the generated charts, etc.
Mapbox can also be used within ggplotly. However, one drawback is that it needs an api key to be generated for full usage. It has various advantages including more detailed view - aerial, etc. that can be useful for airbnb future rentors when they want to see nearby shops and such that may be available.
The code chunks below installs and launches these R packages into R environment.
Geospatial Data Wrangling
Importing geospatial data
The geospatial data used in this hands-on exercise is called MP14_SUBZONE_WEB_PL. It is in ESRI shapefile format. The shapefile consists of URA Master Plan 2014’s planning subzone boundaries. Polygon features are used to represent these geographic boundaries. The GIS data is in svy21 projected coordinates systems.
The code chunk below is used to import MP_SUBZONE_WEB_PL shapefile by using st_read() of sf packages.
mpsz = st_read(dsn = "../../data/geospatial/week10", layer = "MP14_SUBZONE_WEB_PL")Reading layer `MP14_SUBZONE_WEB_PL' from data source
`/Users/maarunipandithurai/Documents/Documents - Maaruni’s MacBook Pro/maars202/geospatial/IS415-GAA/data/geospatial/week10'
using driver `ESRI Shapefile'
Simple feature collection with 323 features and 15 fields
Geometry type: MULTIPOLYGON
Dimension: XY
Bounding box: xmin: 2667.538 ymin: 15748.72 xmax: 56396.44 ymax: 50256.33
Projected CRS: SVY21
The report above shows that the R object used to contain the imported MP14_SUBZONE_WEB_PL shapefile is called mpsz and it is a simple feature object. The geometry type is multipolygon. it is also important to note that mpsz simple feature object does not have EPSG information.
Updating CRS information
The code chunk below updates the newly imported mpsz with the correct ESPG code (i.e. 3414)
mpsz_svy21 <- st_transform(mpsz, 3414)After transforming the projection metadata, you can varify the projection of the newly transformed mpsz_svy21 by using st_crs() of sf package.
The code chunk below will be used to varify the newly transformed mpsz_svy21.
st_crs(mpsz_svy21)Coordinate Reference System:
User input: EPSG:3414
wkt:
PROJCRS["SVY21 / Singapore TM",
BASEGEOGCRS["SVY21",
DATUM["SVY21",
ELLIPSOID["WGS 84",6378137,298.257223563,
LENGTHUNIT["metre",1]]],
PRIMEM["Greenwich",0,
ANGLEUNIT["degree",0.0174532925199433]],
ID["EPSG",4757]],
CONVERSION["Singapore Transverse Mercator",
METHOD["Transverse Mercator",
ID["EPSG",9807]],
PARAMETER["Latitude of natural origin",1.36666666666667,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8801]],
PARAMETER["Longitude of natural origin",103.833333333333,
ANGLEUNIT["degree",0.0174532925199433],
ID["EPSG",8802]],
PARAMETER["Scale factor at natural origin",1,
SCALEUNIT["unity",1],
ID["EPSG",8805]],
PARAMETER["False easting",28001.642,
LENGTHUNIT["metre",1],
ID["EPSG",8806]],
PARAMETER["False northing",38744.572,
LENGTHUNIT["metre",1],
ID["EPSG",8807]]],
CS[Cartesian,2],
AXIS["northing (N)",north,
ORDER[1],
LENGTHUNIT["metre",1]],
AXIS["easting (E)",east,
ORDER[2],
LENGTHUNIT["metre",1]],
USAGE[
SCOPE["Cadastre, engineering survey, topographic mapping."],
AREA["Singapore - onshore and offshore."],
BBOX[1.13,103.59,1.47,104.07]],
ID["EPSG",3414]]
Notice that the EPSG: is indicated as 3414 now.
Next, you will reveal the extent of mpsz_svy21 by using st_bbox() of sf package.
st_bbox(mpsz_svy21) #view extent xmin ymin xmax ymax
2667.538 15748.721 56396.440 50256.334
Aspatial Data Wrangling of Airbnb
Importing the aspatial data
The listings.csv is in csv file format. The codes chunk below uses read_csv() function of readr package to import listings.csv into R as a tibble data frame called airbnb_resale.
airbnb_resale = read_csv("data2/listings.csv")
glimpse(airbnb_resale)Rows: 3,457
Columns: 18
$ id <dbl> 71609, 71896, 71903, 275343, 275344, 28…
$ name <chr> "Villa in Singapore · ★4.44 · 2 bedroom…
$ host_id <dbl> 367042, 367042, 367042, 1439258, 143925…
$ host_name <chr> "Belinda", "Belinda", "Belinda", "Kay",…
$ neighbourhood_group <chr> "East Region", "East Region", "East Reg…
$ neighbourhood <chr> "Tampines", "Tampines", "Tampines", "Bu…
$ latitude <dbl> 1.34537, 1.34754, 1.34531, 1.29015, 1.2…
$ longitude <dbl> 103.9589, 103.9596, 103.9610, 103.8081,…
$ room_type <chr> "Private room", "Private room", "Privat…
$ price <dbl> 150, 80, 80, 64, 78, 220, 85, 75, 69, 7…
$ minimum_nights <dbl> 92, 92, 92, 60, 60, 92, 92, 60, 60, 92,…
$ number_of_reviews <dbl> 19, 24, 46, 20, 16, 12, 131, 17, 5, 81,…
$ last_review <chr> "17/1/20", "13/10/19", "9/1/20", "13/8/…
$ reviews_per_month <dbl> 0.13, 0.16, 0.30, 0.15, 0.11, 0.09, 0.9…
$ calculated_host_listings_count <dbl> 5, 5, 5, 51, 51, 5, 7, 51, 51, 7, 7, 1,…
$ availability_365 <dbl> 55, 91, 91, 183, 183, 54, 365, 183, 183…
$ number_of_reviews_ltm <dbl> 0, 0, 0, 0, 3, 0, 0, 1, 2, 0, 0, 0, 0, …
$ license <chr> NA, NA, NA, "S0399", "S0399", NA, NA, "…
After importing the data file into R, it is important for us to examine if the data file has been imported correctly.
The codes chunks below uses glimpse() to display the data structure of will do the job.
head(airbnb_resale$latitude) #see the data in XCOORD column[1] 1.34537 1.34754 1.34531 1.29015 1.28836 1.34490
head(airbnb_resale$longitude) #see the data in XCOORD column[1] 103.9589 103.9596 103.9610 103.8081 103.8114 103.9598
Next, summary() of base R is used to display the summary statistics of cond_resale tibble data frame.
Converting aspatial data frame into a sf object
Currently, the airbnb_resale tibble data frame is aspatial. We will convert it to a sf object. The code chunk below converts airbnb_resale data frame into a simple feature data frame by using st_as_sf() of sf packages.
airbnb_resale.sf <- st_as_sf(airbnb_resale,
coords = c("longitude", "latitude"),
crs=4326) %>%
st_transform(crs=3414)Notice that st_transform() of sf package is used to convert the coordinates from wgs84 (i.e. crs:4326) to svy21 (i.e. crs=3414).
Next, head() is used to list the content of airbnb_resale.sf object.
head(airbnb_resale.sf)Simple feature collection with 6 features and 16 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 25197.84 ymin: 30085.83 xmax: 42209.55 ymax: 36630.01
Projected CRS: SVY21 / Singapore TM
# A tibble: 6 × 17
id name host_id host_name neighbourhood_group neighbourhood room_type
<dbl> <chr> <dbl> <chr> <chr> <chr> <chr>
1 71609 Villa in… 367042 Belinda East Region Tampines Private …
2 71896 Home in … 367042 Belinda East Region Tampines Private …
3 71903 Home in … 367042 Belinda East Region Tampines Private …
4 275343 Rental u… 1439258 Kay Central Region Bukit Merah Private …
5 275344 Rental u… 1439258 Kay Central Region Bukit Merah Private …
6 289234 Home in … 367042 Belinda East Region Tampines Private …
# ℹ 10 more variables: price <dbl>, minimum_nights <dbl>,
# number_of_reviews <dbl>, last_review <chr>, reviews_per_month <dbl>,
# calculated_host_listings_count <dbl>, availability_365 <dbl>,
# number_of_reviews_ltm <dbl>, license <chr>, geometry <POINT [m]>
Notice that the output is in point feature data frame.
Exploratory Data Analysis (EDA)
In the section, you will learn how to use statistical graphics functions of ggplot2 package to perform EDA.
EDA using statistical graphics
We can plot the distribution of price by using appropriate Exploratory Data Analysis (EDA) as shown in the code chunk below.
ggplot(data=airbnb_resale.sf, aes(x=`price`)) +
geom_histogram(bins=20, color="black", fill="light blue")
The figure above reveals a left skewed distribution. This means that more airbnb units were transacted at relative lower prices.
Statistically, the skewed dsitribution can be normalised by using log transformation. The code chunk below is used to derive a new variable called LOG_SELLING_PRICE by using a log transformation on the variable price.
airbnb_resale.sf <- airbnb_resale.sf %>%
mutate(`LOG_SELLING_PRICE` = log(price))Now, you can plot the LOG_SELLING_PRICE using the code chunk below.
ggplot(data=airbnb_resale.sf, aes(x=`LOG_SELLING_PRICE`)) +
geom_histogram(bins=20, color="black", fill="light blue")
Now, the distribution is relatively less skewed after the transformation.
Multiple Histogram Plots distribution of variables
In this section, you will learn how to draw a small multiple histograms (also known as trellis plot) by using ggarrange() of ggpubr package.
The code chunk below is used to create 12 histograms. Then, ggarrange() is used to organised these histogram into a 3 columns by 4 rows small multiple plot.
NUM_REVIEWS <- ggplot(data=airbnb_resale.sf, aes(x= `number_of_reviews`)) +
geom_histogram(bins=20, color="black", fill="light blue")
MIN_NIGHTS <- ggplot(data=airbnb_resale.sf, aes(x= `minimum_nights`)) +
geom_histogram(bins=20, color="black", fill="light blue")
REVIEWS_PER_MONTH <- ggplot(data=airbnb_resale.sf, aes(x= `reviews_per_month`)) +
geom_histogram(bins=20, color="black", fill="light blue")
CALCULATED_HOST_LISTINGS_COUNT <- ggplot(data=airbnb_resale.sf, aes(x= `calculated_host_listings_count`)) +
geom_histogram(bins=20, color="black", fill="light blue")
AVAILABILITY_365 <- ggplot(data=airbnb_resale.sf, aes(x= `availability_365`)) +
geom_histogram(bins=20, color="black", fill="light blue")
NUM_REVIEWS_LTM <- ggplot(data=airbnb_resale.sf,
aes(x= `number_of_reviews_ltm`)) +
geom_histogram(bins=20, color="black", fill="light blue")
ggarrange(NUM_REVIEWS, MIN_NIGHTS, REVIEWS_PER_MONTH, CALCULATED_HOST_LISTINGS_COUNT, AVAILABILITY_365, NUM_REVIEWS_LTM,
ncol = 3, nrow = 4)
Drawing Statistical Point Map
Lastly, we want to reveal the geospatial distribution airbnb sale prices in Singapore. The map will be prepared by using tmap package.
First, we will turn on the interactive mode of tmap by using the code chunk below.
tmap_mode("view")
tmap_options(check.and.fix = TRUE)Next, the code chunks below is used to create an interactive point symbol map.
tm_shape(mpsz_svy21)+
tm_polygons() +
tm_shape(airbnb_resale.sf) +
tm_dots(col = "price",
alpha = 0.6,
style="quantile") +
tm_view(set.zoom.limits = c(11,14))Notice that tm_dots() is used instead of tm_bubbles().
set.zoom.limits argument of tm_view() sets the minimum and maximum zoom level to 11 and 14 respectively.
Before moving on to the next section, the code below will be used to turn R display into plot mode.
tmap_mode("plot")Hedonic Pricing Modelling in R
In this section, you will learn how to building hedonic pricing models for airbnb rental units using lm() of R base.
Simple Linear Regression Method
First, we will build a simple linear regression model by using PRICE as the dependent variable and reviews_per_month as the independent variable.
names(airbnb_resale) [1] "id" "name"
[3] "host_id" "host_name"
[5] "neighbourhood_group" "neighbourhood"
[7] "latitude" "longitude"
[9] "room_type" "price"
[11] "minimum_nights" "number_of_reviews"
[13] "last_review" "reviews_per_month"
[15] "calculated_host_listings_count" "availability_365"
[17] "number_of_reviews_ltm" "license"
airbnb.slr <- lm(formula=price ~ reviews_per_month, data = airbnb_resale.sf)lm() returns an object of class “lm” or for multiple responses of class c(“mlm”, “lm”).
The functions summary() and anova() can be used to obtain and print a summary and analysis of variance table of the results. The generic accessor functions coefficients, effects, fitted.values and residuals extract various useful features of the value returned by lm.
summary(airbnb.slr)
Call:
lm(formula = price ~ reviews_per_month, data = airbnb_resale.sf)
Residuals:
Min 1Q Median 3Q Max
-200.0 -153.0 -75.9 41.6 10064.3
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 222.123 10.838 20.495 <2e-16 ***
reviews_per_month -6.719 7.290 -0.922 0.357
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 419.4 on 1779 degrees of freedom
(1676 observations deleted due to missingness)
Multiple R-squared: 0.0004773, Adjusted R-squared: -8.458e-05
F-statistic: 0.8495 on 1 and 1779 DF, p-value: 0.3568
relationship is negatively proportional ==> -6.719 x + 222.123 where x is reviews per month. This makes sense since the lower listing price could have led to a higher number of reviews indicates the listing became more popular. With this relationship only explaining 0.0004773, it does not seem very effective.
To visualise the best fit curve on a scatterplot, we can incorporate lm() as a method function in ggplot’s geometry as shown in the code chunk below.
Figure below reveals that there are a few statistical outliers with relatively high selling prices.
ggplot(data=airbnb_resale.sf,
aes(x=`reviews_per_month`, y=`price`)) +
geom_point() +
geom_smooth(method = lm)
Multiple Linear Regression Method
Visualising the relationships of the independent variables
Before building a multiple regression model, it is important to ensure that the indepdent variables used are not highly correlated to each other. If these highly correlated independent variables are used in building a regression model by mistake, the quality of the model will be compromised. This phenomenon is known as multicollinearity in statistics.
Correlation matrix is commonly used to visualise the relationships between the independent variables. Beside the pairs() of R, there are many packages support the display of a correlation matrix. In this section, the corrplot package will be used.
The code chunk below is used to plot a scatterplot matrix of the relationship between the independent variables in airbnb_resale data.frame.
numerical columns that are valid as independent variables.
airbnb_cols = airbnb_resale %>%
select(10:12, 14:17)
airbnb_cols# A tibble: 3,457 × 7
price minimum_nights number_of_reviews reviews_per_month
<dbl> <dbl> <dbl> <dbl>
1 150 92 19 0.13
2 80 92 24 0.16
3 80 92 46 0.3
4 64 60 20 0.15
5 78 60 16 0.11
6 220 92 12 0.09
7 85 92 131 0.9
8 75 60 17 0.12
9 69 60 5 0.04
10 79 92 81 0.65
# ℹ 3,447 more rows
# ℹ 3 more variables: calculated_host_listings_count <dbl>,
# availability_365 <dbl>, number_of_reviews_ltm <dbl>
names(airbnb_cols)[1] "price" "minimum_nights"
[3] "number_of_reviews" "reviews_per_month"
[5] "calculated_host_listings_count" "availability_365"
[7] "number_of_reviews_ltm"
Need to tidy data and impute certain columns with null values with the mean:
print(sum(is.na(airbnb_cols)))[1] 1739
# replacing NA with each column's mean
# using colMeans()
mean_val <- colMeans(airbnb_cols,na.rm = TRUE)
# replacing NA with mean value of each column
for(i in colnames(airbnb_cols))
airbnb_cols[,i][is.na(airbnb_cols[,i])] <- mean_val[i]
print(sum(is.na(airbnb_cols)))[1] 0
corrplot(cor(airbnb_cols), diag = FALSE, order = "AOE",
tl.pos = "td", tl.cex = 0.5, method = "number", type = "upper")
Matrix reorder is very important for mining the hiden structure and patter in the matrix. There are four methods in corrplot (parameter order), named “AOE”, “FPC”, “hclust”, “alphabet”. In the code chunk above, AOE order is used. It orders the variables by using the angular order of the eigenvectors method suggested by Michael Friendly.
From the scatterplot matrix, it is clear that Freehold is highly correlated to LEASE_99YEAR. In view of this, it is wiser to only include either one of them in the subsequent model building. As a result, LEASE_99YEAR is excluded in the subsequent model building.
Building a hedonic pricing model using multiple linear regression method
The code chunk below using lm() to calibrate the multiple linear regression model.
names(airbnb_cols)[1] "price" "minimum_nights"
[3] "number_of_reviews" "reviews_per_month"
[5] "calculated_host_listings_count" "availability_365"
[7] "number_of_reviews_ltm"
airbnb_resale.sfSimple feature collection with 3457 features and 17 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 5881.613 ymin: 22713.81 xmax: 45389.01 ymax: 48821.86
Projected CRS: SVY21 / Singapore TM
# A tibble: 3,457 × 18
id name host_id host_name neighbourhood_group neighbourhood room_type
* <dbl> <chr> <dbl> <chr> <chr> <chr> <chr>
1 71609 Villa i… 367042 Belinda East Region Tampines Private …
2 71896 Home in… 367042 Belinda East Region Tampines Private …
3 71903 Home in… 367042 Belinda East Region Tampines Private …
4 275343 Rental … 1439258 Kay Central Region Bukit Merah Private …
5 275344 Rental … 1439258 Kay Central Region Bukit Merah Private …
6 289234 Home in… 367042 Belinda East Region Tampines Private …
7 294281 Rental … 1521514 Elizabeth Central Region Newton Private …
8 324945 Rental … 1439258 Kay Central Region Bukit Merah Private …
9 330095 Rental … 1439258 Kay Central Region Bukit Merah Private …
10 369141 Place t… 1521514 Elizabeth Central Region Newton Private …
# ℹ 3,447 more rows
# ℹ 11 more variables: price <dbl>, minimum_nights <dbl>,
# number_of_reviews <dbl>, last_review <chr>, reviews_per_month <dbl>,
# calculated_host_listings_count <dbl>, availability_365 <dbl>,
# number_of_reviews_ltm <dbl>, license <chr>, geometry <POINT [m]>,
# LOG_SELLING_PRICE <dbl>
airbnb.mlr <- lm(formula = price ~ minimum_nights + number_of_reviews +
reviews_per_month + calculated_host_listings_count + availability_365 +
number_of_reviews_ltm,
data=airbnb_resale.sf)
summary(airbnb.mlr)
Call:
lm(formula = price ~ minimum_nights + number_of_reviews + reviews_per_month +
calculated_host_listings_count + availability_365 + number_of_reviews_ltm,
data = airbnb_resale.sf)
Residuals:
Min 1Q Median 3Q Max
-317.7 -130.6 -50.5 39.0 10037.3
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 372.46069 24.86924 14.977 < 2e-16 ***
minimum_nights -0.83842 0.14611 -5.738 1.12e-08 ***
number_of_reviews -0.52078 0.29784 -1.749 0.0805 .
reviews_per_month -12.32501 11.81782 -1.043 0.2971
calculated_host_listings_count 0.99796 0.19787 5.044 5.03e-07 ***
availability_365 -0.49606 0.07935 -6.251 5.08e-10 ***
number_of_reviews_ltm 1.01940 0.98674 1.033 0.3017
---
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 409.5 on 1774 degrees of freedom
(1676 observations deleted due to missingness)
Multiple R-squared: 0.04988, Adjusted R-squared: 0.04666
F-statistic: 15.52 on 6 and 1774 DF, p-value: < 2.2e-16
Finding which observations were deleted by model
length(na.action(airbnb.mlr))[1] 1676
Preparing Publication Quality Table: olsrr method
With reference to the report above, it is clear that not all the independent variables are statistically significant. We will revised the model by removing those variables which are not statistically significant.
Now, we are ready to calibrate the revised model by using the code chunk below.
airbnb.mlr1 <- lm(formula = price ~ minimum_nights + number_of_reviews +
reviews_per_month + calculated_host_listings_count + availability_365 +
number_of_reviews_ltm,
data=airbnb_resale.sf)
ols_regress(airbnb.mlr1) Model Summary
--------------------------------------------------------------------
R 0.223 RMSE 408.678
R-Squared 0.050 MSE 167676.525
Adj. R-Squared 0.047 Coef. Var 187.718
Pred R-Squared 0.043 AIC 26488.305
MAE 142.171 SBC 26532.184
--------------------------------------------------------------------
RMSE: Root Mean Square Error
MSE: Mean Square Error
MAE: Mean Absolute Error
AIC: Akaike Information Criteria
SBC: Schwarz Bayesian Criteria
ANOVA
---------------------------------------------------------------------------
Sum of
Squares DF Mean Square F Sig.
---------------------------------------------------------------------------
Regression 15614667.290 6 2602444.548 15.521 0.0000
Residual 297458156.007 1774 167676.525
Total 313072823.297 1780
---------------------------------------------------------------------------
Parameter Estimates
--------------------------------------------------------------------------------------------------------------
model Beta Std. Error Std. Beta t Sig lower upper
--------------------------------------------------------------------------------------------------------------
(Intercept) 372.461 24.869 14.977 0.000 323.685 421.237
minimum_nights -0.838 0.146 -0.139 -5.738 0.000 -1.125 -0.552
number_of_reviews -0.521 0.298 -0.056 -1.749 0.081 -1.105 0.063
reviews_per_month -12.325 11.818 -0.040 -1.043 0.297 -35.503 10.853
calculated_host_listings_count 0.998 0.198 0.125 5.044 0.000 0.610 1.386
availability_365 -0.496 0.079 -0.153 -6.251 0.000 -0.652 -0.340
number_of_reviews_ltm 1.019 0.987 0.041 1.033 0.302 -0.916 2.955
--------------------------------------------------------------------------------------------------------------
Preparing Publication Quality Table: gtsummary method
The gtsummary package provides an elegant and flexible way to create publication-ready summary tables in R.
In the code chunk below, tbl_regression() is used to create a well formatted regression report.
tbl_regression(airbnb.mlr1, intercept = TRUE)| Characteristic | Beta | 95% CI1 | p-value |
|---|---|---|---|
| (Intercept) | 372 | 324, 421 | <0.001 |
| minimum_nights | -0.84 | -1.1, -0.55 | <0.001 |
| number_of_reviews | -0.52 | -1.1, 0.06 | 0.081 |
| reviews_per_month | -12 | -36, 11 | 0.3 |
| calculated_host_listings_count | 1.0 | 0.61, 1.4 | <0.001 |
| availability_365 | -0.50 | -0.65, -0.34 | <0.001 |
| number_of_reviews_ltm | 1.0 | -0.92, 3.0 | 0.3 |
| 1 CI = Confidence Interval | |||
With gtsummary package, model statistics can be included in the report by either appending them to the report table by using add_glance_table() or adding as a table source note by using add_glance_source_note() as shown in the code chunk below.
tbl_regression(airbnb.mlr1,
intercept = TRUE) %>%
add_glance_source_note(
label = list(sigma ~ "\U03C3"),
include = c(r.squared, adj.r.squared,
AIC, statistic,
p.value, sigma))| Characteristic | Beta | 95% CI1 | p-value |
|---|---|---|---|
| (Intercept) | 372 | 324, 421 | <0.001 |
| minimum_nights | -0.84 | -1.1, -0.55 | <0.001 |
| number_of_reviews | -0.52 | -1.1, 0.06 | 0.081 |
| reviews_per_month | -12 | -36, 11 | 0.3 |
| calculated_host_listings_count | 1.0 | 0.61, 1.4 | <0.001 |
| availability_365 | -0.50 | -0.65, -0.34 | <0.001 |
| number_of_reviews_ltm | 1.0 | -0.92, 3.0 | 0.3 |
| R² = 0.050; Adjusted R² = 0.047; AIC = 26,488; Statistic = 15.5; p-value = <0.001; σ = 409 | |||
| 1 CI = Confidence Interval | |||
For more customisation options, refer to Tutorial: tbl_regression
Checking for multicolinearity
In this section, we would like to introduce you a fantastic R package specially programmed for performing OLS regression. It is called olsrr. It provides a collection of very useful methods for building better multiple linear regression models:
comprehensive regression output
residual diagnostics
measures of influence
heteroskedasticity tests
collinearity diagnostics
model fit assessment
variable contribution assessment
variable selection procedures
In the code chunk below, the ols_vif_tol() of olsrr package is used to test if there are sign of multicollinearity.
ols_vif_tol(airbnb.mlr1) Variables Tolerance VIF
1 minimum_nights 0.9169482 1.090574
2 number_of_reviews 0.5250273 1.904663
3 reviews_per_month 0.3627705 2.756564
4 calculated_host_listings_count 0.8711919 1.147853
5 availability_365 0.8915016 1.121703
6 number_of_reviews_ltm 0.3472839 2.879488
Since the VIF of the independent variables are less than 10. We can safely conclude that there are no sign of multicollinearity among the independent variables.
Test for Non-Linearity
In multiple linear regression, it is important for us to test the assumption that linearity and additivity of the relationship between dependent and independent variables.
In the code chunk below, the ols_plot_resid_fit() of olsrr package is used to perform linearity assumption test.
ols_plot_resid_fit(airbnb.mlr1)
The figure above reveals that most of the data poitns are scattered around the 0 line, hence we can safely conclude that the relationships between the dependent variable and independent variables are linear.
Test for Normality Assumption
Lastly, the code chunk below uses ols_plot_resid_hist() of olsrr package to perform normality assumption test.
ols_plot_resid_hist(airbnb.mlr1)
The figure reveals that the residual of the multiple linear regression model (i.e. condo.mlr1) is resemble normal distribution.
If you prefer formal statistical test methods, the ols_test_normality() of olsrr package can
ols_test_normality(airbnb.mlr1)-----------------------------------------------
Test Statistic pvalue
-----------------------------------------------
Shapiro-Wilk 0.2817 0.0000
Kolmogorov-Smirnov 0.2612 0.0000
Cramer-von Mises 190.7087 0.0000
Anderson-Darling 277.0846 0.0000
-----------------------------------------------
The summary table above reveals that the p-values of the four tests are way smaller than the alpha value of 0.05. Hence we will reject the null hypothesis and infer that there is statistical evidence that the residual are not normally distributed.
Multiple Linear Regression model created and can be used for prediction.
These results will be displayed on Shiny app.
Testing for Spatial Autocorrelation
The hedonic model we try to build are using geographically referenced attributes, hence it is also important for us to visual the residual of the hedonic pricing model.
In order to perform spatial autocorrelation test, we need to convert airbnb_resale.sf from sf data frame into a SpatialPointsDataFrame.
First, we will export the residual of the hedonic pricing model and save it as a data frame.
airbnb.mlr.output <- as.data.frame(airbnb.mlr1$residuals)Next, we will join the newly created data frame with condo_resale.sf object.
head(airbnb_resale.sf)Simple feature collection with 6 features and 17 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 25197.84 ymin: 30085.83 xmax: 42209.55 ymax: 36630.01
Projected CRS: SVY21 / Singapore TM
# A tibble: 6 × 18
id name host_id host_name neighbourhood_group neighbourhood room_type
<dbl> <chr> <dbl> <chr> <chr> <chr> <chr>
1 71609 Villa in… 367042 Belinda East Region Tampines Private …
2 71896 Home in … 367042 Belinda East Region Tampines Private …
3 71903 Home in … 367042 Belinda East Region Tampines Private …
4 275343 Rental u… 1439258 Kay Central Region Bukit Merah Private …
5 275344 Rental u… 1439258 Kay Central Region Bukit Merah Private …
6 289234 Home in … 367042 Belinda East Region Tampines Private …
# ℹ 11 more variables: price <dbl>, minimum_nights <dbl>,
# number_of_reviews <dbl>, last_review <chr>, reviews_per_month <dbl>,
# calculated_host_listings_count <dbl>, availability_365 <dbl>,
# number_of_reviews_ltm <dbl>, license <chr>, geometry <POINT [m]>,
# LOG_SELLING_PRICE <dbl>
#airbnb_resale.sf$index
nrow(airbnb_resale.sf)[1] 3457
# Convert rownames to a column
airbnb_resale.sf<- rownames_to_column(airbnb_resale.sf, var = "row_index")
# View the modified dataset
print(airbnb_resale.sf)Simple feature collection with 3457 features and 18 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 5881.613 ymin: 22713.81 xmax: 45389.01 ymax: 48821.86
Projected CRS: SVY21 / Singapore TM
# A tibble: 3,457 × 19
row_index id name host_id host_name neighbourhood_group neighbourhood
<chr> <dbl> <chr> <dbl> <chr> <chr> <chr>
1 1 71609 Villa i… 367042 Belinda East Region Tampines
2 2 71896 Home in… 367042 Belinda East Region Tampines
3 3 71903 Home in… 367042 Belinda East Region Tampines
4 4 275343 Rental … 1439258 Kay Central Region Bukit Merah
5 5 275344 Rental … 1439258 Kay Central Region Bukit Merah
6 6 289234 Home in… 367042 Belinda East Region Tampines
7 7 294281 Rental … 1521514 Elizabeth Central Region Newton
8 8 324945 Rental … 1439258 Kay Central Region Bukit Merah
9 9 330095 Rental … 1439258 Kay Central Region Bukit Merah
10 10 369141 Place t… 1521514 Elizabeth Central Region Newton
# ℹ 3,447 more rows
# ℹ 12 more variables: room_type <chr>, price <dbl>, minimum_nights <dbl>,
# number_of_reviews <dbl>, last_review <chr>, reviews_per_month <dbl>,
# calculated_host_listings_count <dbl>, availability_365 <dbl>,
# number_of_reviews_ltm <dbl>, license <chr>, geometry <POINT [m]>,
# LOG_SELLING_PRICE <dbl>
airbnb_resale.sf <- airbnb_resale.sf[!airbnb_resale.sf$row_index %in% na.action(airbnb.mlr), ]
length(na.action(airbnb.mlr))[1] 1676
#na.action(airbnb.mlr)#length(airbnb.mlr1$na.action)length(airbnb.mlr1$residuals)[1] 1781
airbnb_resale.res.sf <- cbind(airbnb_resale.sf,
airbnb.mlr1$residuals) %>%
rename(`MLR_RES` = `airbnb.mlr1.residuals`)Next, we will convert condo_resale.res.sf from simple feature object into a SpatialPointsDataFrame because spdep package can only process sp conformed spatial data objects.
The code chunk below will be used to perform the data conversion process.
airbnb_resale.sp <- as_Spatial(airbnb_resale.res.sf)
airbnb_resale.spclass : SpatialPointsDataFrame
features : 1781
extent : 7406.989, 44988.07, 22840.48, 48297.96 (xmin, xmax, ymin, ymax)
crs : +proj=tmerc +lat_0=1.36666666666667 +lon_0=103.833333333333 +k=1 +x_0=28001.642 +y_0=38744.572 +ellps=WGS84 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs
variables : 19
names : row_index, id, name, host_id, host_name, neighbourhood_group, neighbourhood, room_type, price, minimum_nights, number_of_reviews, last_review, reviews_per_month, calculated_host_listings_count, availability_365, ...
min values : 1, 71609, Aparthotel in Singapore · ★4.36 · Studio · 1 bed · 1 bath, 23666, Accomodation, Central Region, Ang Mo Kio, Entire home/apt, 22, 1, 1, 1/1/18, 0.01, 1, 0, ...
max values : 998, 1029731383146744192, Villa in Singapore · 1 bedroom · 2 beds · 1 private bath, 542352890, 静, West Region, Yishun, Shared room, 10286, 1000, 757, 9/9/23, 29.62, 260, 365, ...
tmap_mode("view")tm_shape(mpsz_svy21)+
tmap_options(check.and.fix = TRUE) +
tm_polygons(alpha = 0.4) +
tm_shape(airbnb_resale.res.sf) +
tm_dots(col = "MLR_RES",
alpha = 0.6,
style="quantile") +
tm_view(set.zoom.limits = c(11,14))tmap_mode("plot")nb <- dnearneigh(coordinates(airbnb_resale.sp), 0, 1, longlat = FALSE)
summary(nb)Neighbour list object:
Number of regions: 1781
Number of nonzero links: 1722
Percentage nonzero weights: 0.05428818
Average number of links: 0.9668725
1549 regions with no links:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28
29 30 31 32 33 34 36 40 41 42 43 44 45 46 47 48 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
106 107 108 110 112 113 114 115 116 117 118 119 120 121 122 123 124 125
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 162
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 179 180 181
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199
200 201 202 203 204 205 206 207 208 210 212 216 217 218 219 220 221 222
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
241 242 243 251 253 254 255 256 257 258 259 260 261 262 263 264 265 266
267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 302 303
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339
340 341 343 344 345 346 347 348 350 351 352 353 354 355 356 357 360 361
362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379
380 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398
399 400 401 402 403 404 405 411 412 413 414 415 416 417 418 419 420 421
422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475
476 477 478 479 486 487 488 489 490 491 492 493 494 496 497 498 500 501
502 503 504 505 507 508 509 512 513 514 515 516 517 519 520 522 523 524
525 526 527 528 529 531 532 533 534 535 536 537 538 539 540 541 542 543
544 545 546 547 548 549 550 551 552 553 556 557 558 559 560 562 563 564
565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582
583 584 585 586 587 588 590 591 592 593 594 595 596 597 598 599 600 601
602 603 604 605 606 607 608 609 610 611 612 614 615 616 617 618 619 620
621 622 623 624 625 626 627 628 630 632 633 634 635 636 637 638 639 640
641 642 643 644 646 647 648 649 650 651 652 653 654 655 656 657 659 660
663 664 665 666 667 668 669 670 671 673 674 675 676 677 678 679 680 681
682 683 685 686 687 688 689 690 691 692 695 696 697 698 699 700 701 702
703 704 705 706 707 708 709 710 713 714 715 716 719 722 723 726 727 728
729 730 731 733 735 736 737 738 739 740 741 742 743 744 745 746 747 748
749 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767
768 769 770 771 773 774 775 776 777 778 780 782 785 786 787 788 790 792
793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810
811 812 813 814 815 818 819 820 821 822 823 824 825 826 829 830 831 833
834 835 836 837 838 839 840 841 842 843 844 846 847 850 851 852 853 854
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
891 892 894 895 896 897 898 899 900 901 902 903 907 908 909 910 911 912
913 915 916 917 918 919 920 921 922 923 924 927 929 931 932 933 934 935
936 937 938 939 940 942 943 944 945 946 947 948 949 950 951 952 953 954
955 956 957 958 959 960 961 962 963 964 965 966 967 968 970 971 972 973
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991
992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1008
1009 1010 1011 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023
1025 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053
1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081
1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109
1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123
1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151
1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165
1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179
1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193
1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207
1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221
1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235
1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277
1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1290 1291 1293 1294
1295 1298 1299 1300 1301 1306 1307 1308 1311 1314 1322 1323 1324 1325
1326 1327 1328 1329 1330 1333 1334 1335 1336 1337 1338 1339 1340 1341
1342 1343 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356
1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370
1371 1372 1373 1374 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385
1386 1387 1388 1389 1390 1391 1392 1393 1395 1396 1397 1398 1399 1400
1401 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430
1431 1432 1433 1434 1440 1442 1443 1445 1447 1448 1449 1450 1451 1454
1455 1456 1457 1458 1459 1462 1463 1466 1469 1473 1474 1475 1476 1477
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491
1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505
1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1520 1524 1525
1526 1527 1528 1537 1539 1540 1541 1542 1543 1544 1545 1546 1549 1551
1552 1556 1557 1558 1559 1560 1564 1565 1566 1567 1568 1569 1570 1571
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585
1586 1590 1591 1592 1593 1594 1595 1596 1599 1600 1601 1602 1603 1604
1605 1607 1609 1611 1612 1614 1616 1623 1625 1631 1632 1633 1634 1635
1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649
1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663
1664 1665 1666 1667 1668 1669 1672 1673 1675 1676 1679 1680 1681 1682
1685 1687 1689 1690 1691 1692 1693 1694 1695 1696 1697 1699 1701 1702
1703 1708 1709 1710 1711 1712 1714 1715 1716 1717 1718 1719 1720 1721
1722 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1738 1741 1747
1748 1749 1750 1751 1752 1753 1756 1757 1758 1759 1760 1761 1762 1763
1764 1765 1766 1767 1769 1770 1771 1772 1774 1775 1776 1777 1778 1779
1781
1597 disjoint connected subgraphs
Link number distribution:
0 1 2 3 4 5 6 8 9 11 13 23
1549 34 30 16 10 24 35 9 10 12 28 24
34 least connected regions:
111 161 495 499 510 511 589 661 662 684 718 720 925 930 1007 1012 1024 1026 1446 1452 1453 1465 1538 1547 1548 1561 1606 1608 1626 1627 1698 1700 1713 1768 with 1 link
24 most connected regions:
1288 1289 1292 1296 1297 1302 1303 1304 1305 1309 1310 1312 1313 1315 1316 1317 1318 1319 1320 1321 1331 1332 1344 1375 with 23 links
#lm.morantest(condo.mlr1, nb_lw)#nb_lw <- nb2listw(nb, style = 'W')
#summary(nb_lw)bw.fixed <- bw.gwr(formula = price ~ minimum_nights + number_of_reviews +
reviews_per_month + calculated_host_listings_count + availability_365 +
number_of_reviews_ltm,
data=airbnb_resale.sp,
approach="CV",
kernel="gaussian",
adaptive=FALSE,
longlat=FALSE)Take a cup of tea and have a break, it will take a few minutes.
-----A kind suggestion from GWmodel development group
Fixed bandwidth: 23731.77 CV score: 299608053
Fixed bandwidth: 14669.97 CV score: 299780431
Fixed bandwidth: 29332.26 CV score: 299571637
Fixed bandwidth: 32793.56 CV score: 299557106
Fixed bandwidth: 34932.76 CV score: 299550012
Fixed bandwidth: 36254.86 CV score: 299546186
Fixed bandwidth: 37071.96 CV score: 299544005
Fixed bandwidth: 37576.96 CV score: 299542721
Fixed bandwidth: 37889.06 CV score: 299541951
Fixed bandwidth: 38081.96 CV score: 299541484
Fixed bandwidth: 38201.17 CV score: 299541198
Fixed bandwidth: 38274.85 CV score: 299541023
Fixed bandwidth: 38320.38 CV score: 299540915
Fixed bandwidth: 38348.52 CV score: 299540849
Fixed bandwidth: 38365.92 CV score: 299540808
Fixed bandwidth: 38376.67 CV score: 299540782
Fixed bandwidth: 38383.31 CV score: 299540767
Fixed bandwidth: 38387.42 CV score: 299540757
Fixed bandwidth: 38389.95 CV score: 299540751
Fixed bandwidth: 38391.52 CV score: 299540748
Fixed bandwidth: 38392.49 CV score: 299540745
Fixed bandwidth: 38393.09 CV score: 299540744
Fixed bandwidth: 38393.46 CV score: 299540743
Fixed bandwidth: 38393.69 CV score: 299540742
Fixed bandwidth: 38393.83 CV score: 299540742
Fixed bandwidth: 38393.92 CV score: 299540742
Fixed bandwidth: 38393.97 CV score: 299540742
Fixed bandwidth: 38394.01 CV score: 299540742
Fixed bandwidth: 38394.03 CV score: 299540742
Fixed bandwidth: 38394.04 CV score: 299540742
Fixed bandwidth: 38394.05 CV score: 299540742
Fixed bandwidth: 38394.05 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
Fixed bandwidth: 38394.06 CV score: 299540742
gwr.fixed <- gwr.basic(formula = price ~ minimum_nights + number_of_reviews +
reviews_per_month + calculated_host_listings_count + availability_365 +
number_of_reviews_ltm,
data=airbnb_resale.sp,
bw=bw.fixed,
kernel = 'gaussian',
longlat = FALSE)gwr.fixed ***********************************************************************
* Package GWmodel *
***********************************************************************
Program starts at: 2024-04-07 11:22:11.074587
Call:
gwr.basic(formula = price ~ minimum_nights + number_of_reviews +
reviews_per_month + calculated_host_listings_count + availability_365 +
number_of_reviews_ltm, data = airbnb_resale.sp, bw = bw.fixed,
kernel = "gaussian", longlat = FALSE)
Dependent (y) variable: price
Independent variables: minimum_nights number_of_reviews reviews_per_month calculated_host_listings_count availability_365 number_of_reviews_ltm
Number of data points: 1781
***********************************************************************
* Results of Global Regression *
***********************************************************************
Call:
lm(formula = formula, data = data)
Residuals:
Min 1Q Median 3Q Max
-317.7 -130.6 -50.5 39.0 10037.3
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 372.46069 24.86924 14.977 < 2e-16 ***
minimum_nights -0.83842 0.14611 -5.738 1.12e-08 ***
number_of_reviews -0.52078 0.29784 -1.749 0.0805 .
reviews_per_month -12.32501 11.81782 -1.043 0.2971
calculated_host_listings_count 0.99796 0.19787 5.044 5.03e-07 ***
availability_365 -0.49606 0.07935 -6.251 5.08e-10 ***
number_of_reviews_ltm 1.01940 0.98674 1.033 0.3017
---Significance stars
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 409.5 on 1774 degrees of freedom
Multiple R-squared: 0.04988
Adjusted R-squared: 0.04666
F-statistic: 15.52 on 6 and 1774 DF, p-value: < 2.2e-16
***Extra Diagnostic information
Residual sum of squares: 297458156
Sigma(hat): 408.9074
AIC: 26488.3
AICc: 26488.39
BIC: 24811.06
***********************************************************************
* Results of Geographically Weighted Regression *
***********************************************************************
*********************Model calibration information*********************
Kernel function: gaussian
Fixed bandwidth: 38394.06
Regression points: the same locations as observations are used.
Distance metric: Euclidean distance metric is used.
****************Summary of GWR coefficient estimates:******************
Min. 1st Qu. Median 3rd Qu.
Intercept 367.91026 370.02238 370.31936 370.66879
minimum_nights -0.84626 -0.84432 -0.84407 -0.84377
number_of_reviews -0.53288 -0.52074 -0.51961 -0.51857
reviews_per_month -12.31031 -11.95454 -11.93873 -11.91946
calculated_host_listings_count 0.99580 1.00059 1.00100 1.00169
availability_365 -0.49302 -0.49018 -0.48962 -0.48921
number_of_reviews_ltm 0.98744 0.99959 1.00089 1.00217
Max.
Intercept 372.3968
minimum_nights -0.8397
number_of_reviews -0.5083
reviews_per_month -11.7816
calculated_host_listings_count 1.0093
availability_365 -0.4853
number_of_reviews_ltm 1.0323
************************Diagnostic information*************************
Number of data points: 1781
Effective number of parameters (2trace(S) - trace(S'S)): 7.210602
Effective degrees of freedom (n-2trace(S) + trace(S'S)): 1773.789
AICc (GWR book, Fotheringham, et al. 2002, p. 61, eq 2.33): 26488.21
AIC (GWR book, Fotheringham, et al. 2002,GWR p. 96, eq. 4.22): 26479.02
BIC (GWR book, Fotheringham, et al. 2002,GWR p. 61, eq. 2.34): 24744.11
Residual sum of squares: 297392850
R-square value: 0.05008411
Adjusted R-square value: 0.04622044
***********************************************************************
Program stops at: 2024-04-07 11:22:11.638705
13.9.2 Building Adaptive Bandwidth GWR Model
In this section, we will calibrate the gwr-based hedonic pricing model by using adaptive bandwidth approach.
13.9.2.1 Computing the adaptive bandwidth
Similar to the earlier section, we will first use bw.gwr() to determine the recommended data point to use.
The code chunk used look very similar to the one used to compute the fixed bandwidth except the adaptive argument has changed to TRUE.
bw.adaptive <- bw.gwr(formula = price ~ minimum_nights + number_of_reviews +
reviews_per_month + calculated_host_listings_count + availability_365 +
number_of_reviews_ltm,
data=airbnb_resale.sp,
approach="CV",
kernel="gaussian",
adaptive=TRUE,
longlat=FALSE)Take a cup of tea and have a break, it will take a few minutes.
-----A kind suggestion from GWmodel development group
Adaptive bandwidth: 1108 CV score: 297417623
Adaptive bandwidth: 693 CV score: 295916169
Adaptive bandwidth: 435 CV score: 294209259
Adaptive bandwidth: 277 CV score: 293434984
Adaptive bandwidth: 178 CV score: 292596675
Adaptive bandwidth: 118 CV score: 291673250
Adaptive bandwidth: 79 CV score: 290516597
Adaptive bandwidth: 57 CV score: 287491587
Adaptive bandwidth: 41 CV score: 286793427
Adaptive bandwidth: 33 CV score: 286928247
Adaptive bandwidth: 47 CV score: 287403501
Adaptive bandwidth: 38 CV score: 286669979
Adaptive bandwidth: 35 CV score: 286647755
Adaptive bandwidth: 34 CV score: 286575835
Adaptive bandwidth: 32 CV score: 287065295
Adaptive bandwidth: 33 CV score: 286928247
Adaptive bandwidth: 32 CV score: 287065295
Adaptive bandwidth: 32 CV score: 287065295
Adaptive bandwidth: 31 CV score: 287175560
Adaptive bandwidth: 31 CV score: 287175560
Adaptive bandwidth: 30 CV score: 286828700
Adaptive bandwidth: 30 CV score: 286828700
Adaptive bandwidth: 29 CV score: 286822057
Adaptive bandwidth: 29 CV score: 286822057
Adaptive bandwidth: 28 CV score: 286764761
Adaptive bandwidth: 28 CV score: 286764761
Adaptive bandwidth: 27 CV score: 286881536
Adaptive bandwidth: 27 CV score: 286881536
Adaptive bandwidth: 26 CV score: 286860093
Adaptive bandwidth: 26 CV score: 286860093
Adaptive bandwidth: 25 CV score: 286806536
Adaptive bandwidth: 25 CV score: 286806536
Adaptive bandwidth: 24 CV score: 325773079
Adaptive bandwidth: 24 CV score: 325773079
Adaptive bandwidth: 23 CV score: 325411484
Adaptive bandwidth: 23 CV score: 325411484
13.9.2.2 Constructing the adaptive bandwidth gwr model
Now, we can go ahead to calibrate the gwr-based hedonic pricing model by using adaptive bandwidth and gaussian kernel as shown in the code chunk below.
gwr.adaptive <- gwr.basic(formula = price ~ minimum_nights + number_of_reviews +
reviews_per_month + calculated_host_listings_count + availability_365 +
number_of_reviews_ltm,
data=airbnb_resale.sp, bw=bw.adaptive,
kernel = 'gaussian',
adaptive=TRUE,
longlat = FALSE)gwr.adaptive ***********************************************************************
* Package GWmodel *
***********************************************************************
Program starts at: 2024-04-07 11:22:25.774862
Call:
gwr.basic(formula = price ~ minimum_nights + number_of_reviews +
reviews_per_month + calculated_host_listings_count + availability_365 +
number_of_reviews_ltm, data = airbnb_resale.sp, bw = bw.adaptive,
kernel = "gaussian", adaptive = TRUE, longlat = FALSE)
Dependent (y) variable: price
Independent variables: minimum_nights number_of_reviews reviews_per_month calculated_host_listings_count availability_365 number_of_reviews_ltm
Number of data points: 1781
***********************************************************************
* Results of Global Regression *
***********************************************************************
Call:
lm(formula = formula, data = data)
Residuals:
Min 1Q Median 3Q Max
-317.7 -130.6 -50.5 39.0 10037.3
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 372.46069 24.86924 14.977 < 2e-16 ***
minimum_nights -0.83842 0.14611 -5.738 1.12e-08 ***
number_of_reviews -0.52078 0.29784 -1.749 0.0805 .
reviews_per_month -12.32501 11.81782 -1.043 0.2971
calculated_host_listings_count 0.99796 0.19787 5.044 5.03e-07 ***
availability_365 -0.49606 0.07935 -6.251 5.08e-10 ***
number_of_reviews_ltm 1.01940 0.98674 1.033 0.3017
---Significance stars
Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Residual standard error: 409.5 on 1774 degrees of freedom
Multiple R-squared: 0.04988
Adjusted R-squared: 0.04666
F-statistic: 15.52 on 6 and 1774 DF, p-value: < 2.2e-16
***Extra Diagnostic information
Residual sum of squares: 297458156
Sigma(hat): 408.9074
AIC: 26488.3
AICc: 26488.39
BIC: 24811.06
***********************************************************************
* Results of Geographically Weighted Regression *
***********************************************************************
*********************Model calibration information*********************
Kernel function: gaussian
Adaptive bandwidth: 34 (number of nearest neighbours)
Regression points: the same locations as observations are used.
Distance metric: Euclidean distance metric is used.
****************Summary of GWR coefficient estimates:******************
Min. 1st Qu. Median 3rd Qu.
Intercept 39.28307 216.82777 325.96848 456.86238
minimum_nights -4.66527 -1.87252 -0.69056 -0.31491
number_of_reviews -5.43091 -0.83813 -0.43279 0.15335
reviews_per_month -153.22315 -33.41952 -11.38711 1.32533
calculated_host_listings_count -5.49060 -0.28003 0.46893 1.20408
availability_365 -9.22854 -0.63582 -0.33789 -0.09904
number_of_reviews_ltm -21.08083 -1.22920 0.63488 2.05394
Max.
Intercept 3302.4349
minimum_nights 5.2452
number_of_reviews 2.0539
reviews_per_month 96.8282
calculated_host_listings_count 2.6086
availability_365 0.3040
number_of_reviews_ltm 17.2911
************************Diagnostic information*************************
Number of data points: 1781
Effective number of parameters (2trace(S) - trace(S'S)): 224.9012
Effective degrees of freedom (n-2trace(S) + trace(S'S)): 1556.099
AICc (GWR book, Fotheringham, et al. 2002, p. 61, eq 2.33): 26414.62
AIC (GWR book, Fotheringham, et al. 2002,GWR p. 96, eq. 4.22): 26204.39
BIC (GWR book, Fotheringham, et al. 2002,GWR p. 61, eq. 2.34): 25533.28
Residual sum of squares: 232467337
R-square value: 0.2574656
Adjusted R-square value: 0.150079
***********************************************************************
Program stops at: 2024-04-07 11:22:26.55356
This shows that adaptive is much better!.
13.9.3 Visualising GWR Output
In addition to regression residuals, the output feature class table includes fields for observed and predicted y values, condition number (cond), Local R2, residuals, and explanatory variable coefficients and standard errors:
Condition Number: this diagnostic evaluates local collinearity. In the presence of strong local collinearity, results become unstable. Results associated with condition numbers larger than 30, may be unreliable.
Local R2: these values range between 0.0 and 1.0 and indicate how well the local regression model fits observed y values. Very low values indicate the local model is performing poorly. Mapping the Local R2 values to see where GWR predicts well and where it predicts poorly may provide clues about important variables that may be missing from the regression model.
Predicted: these are the estimated (or fitted) y values 3. computed by GWR.
Residuals: to obtain the residual values, the fitted y values are subtracted from the observed y values. Standardized residuals have a mean of zero and a standard deviation of 1. A cold-to-hot rendered map of standardized residuals can be produce by using these values.
Coefficient Standard Error: these values measure the reliability of each coefficient estimate. Confidence in those estimates are higher when standard errors are small in relation to the actual coefficient values. Large standard errors may indicate problems with local collinearity.
They are all stored in a SpatialPointsDataFrame or SpatialPolygonsDataFrame object integrated with fit.points, GWR coefficient estimates, y value, predicted values, coefficient standard errors and t-values in its “data” slot in an object called SDF of the output list.
13.9.4 Converting SDF into sf data.frame
To visualise the fields in SDF, we need to first covert it into sf data.frame by using the code chunk below.
airbnb_resale.sf.adaptive <- st_as_sf(gwr.adaptive$SDF) %>%
st_transform(crs=3414)airbnb_resale.sf.adaptive.svy21 <- st_transform(airbnb_resale.sf.adaptive, 3414)
airbnb_resale.sf.adaptive.svy21 Simple feature collection with 1781 features and 27 fields
Geometry type: POINT
Dimension: XY
Bounding box: xmin: 7406.989 ymin: 22840.48 xmax: 44988.07 ymax: 48297.96
Projected CRS: SVY21 / Singapore TM
First 10 features:
Intercept minimum_nights number_of_reviews reviews_per_month
1 500.2508 -0.5390498 0.009569676 -74.70184
2 551.2260 -0.5849575 0.229994448 -103.84083
3 504.1947 -0.5331751 -0.023931971 -72.08013
4 381.2089 -0.7652471 -0.562695340 -11.30782
5 388.1380 -0.7007953 -0.564673628 -12.32751
6 493.2534 -0.5288621 -0.039032933 -68.96146
7 494.5930 -2.4087395 -0.330135230 -21.93698
8 385.5914 -0.7132598 -0.568855482 -12.02985
9 387.6518 -0.6608751 -0.580034227 -12.55854
10 507.2315 -2.4290804 -0.255984502 -25.87164
calculated_host_listings_count availability_365 number_of_reviews_ltm y
1 -1.441490 -0.9060696 3.0939149 150
2 -1.942792 -1.0346010 4.4876859 80
3 -1.366769 -0.9227310 3.0025573 80
4 1.322419 -0.4991901 1.0152007 64
5 1.365279 -0.5273875 1.0771012 78
6 -1.323489 -0.8914580 2.8729178 220
7 1.272072 -0.5268931 0.1135791 85
8 1.335117 -0.5173105 1.0679613 75
9 1.328063 -0.5282905 1.1242431 69
10 1.329349 -0.5626775 0.1489773 79
yhat residual CV_Score Stud_residual Intercept_SE minimum_nights_SE
1 384.08755 -234.08755 0 -0.6286180 93.67751 0.5836356
2 382.45264 -302.45264 0 -0.8119813 105.61418 0.6871031
3 341.61531 -261.61531 0 -0.6989346 91.15034 0.5579039
4 298.43555 -234.43555 0 -0.6103546 39.63479 0.2851037
5 312.04810 -234.04810 0 -0.6101275 42.00012 0.3057804
6 383.16699 -163.16699 0 -0.4372438 90.27178 0.5520414
7 26.58644 58.41356 0 0.1618568 48.40814 0.4013770
8 306.17282 -231.17282 0 -0.6020945 40.80850 0.2972643
9 317.89933 -248.89933 0 -0.6483893 41.59817 0.3056796
10 50.13293 28.86707 0 0.0771324 50.34103 0.4183991
number_of_reviews_SE reviews_per_month_SE calculated_host_listings_count_SE
1 0.8619440 65.89899 1.2901926
2 1.0777338 94.63347 1.5450354
3 0.8177892 59.16505 1.2215577
4 0.4664507 19.32707 0.2523682
5 0.5067979 21.71739 0.2626421
6 0.8101984 58.29663 1.2116558
7 0.6236287 15.22740 0.3163627
8 0.4871515 20.63716 0.2573040
9 0.4994623 21.44329 0.2602243
10 0.6471761 16.21855 0.3167273
availability_365_SE number_of_reviews_ltm_SE Intercept_TV minimum_nights_TV
1 0.2988917 5.666594 5.340138 -0.9236068
2 0.3270323 8.737099 5.219243 -0.8513388
3 0.2943894 4.938613 5.531463 -0.9556754
4 0.1231422 1.393041 9.618037 -2.6841007
5 0.1300720 1.522299 9.241354 -2.2918251
6 0.2913553 4.885217 5.464093 -0.9580116
7 0.1512250 1.757401 10.217144 -6.0011894
8 0.1264313 1.461946 9.448802 -2.3994131
9 0.1286994 1.505077 9.318963 -2.1619862
10 0.1558382 1.824689 10.075906 -5.8056540
number_of_reviews_TV reviews_per_month_TV calculated_host_listings_count_TV
1 0.01110243 -1.1335810 -1.117267
2 0.21340561 -1.0972950 -1.257442
3 -0.02926423 -1.2182889 -1.118874
4 -1.20633406 -0.5850768 5.240037
5 -1.11419887 -0.5676332 5.198251
6 -0.04817700 -1.1829409 -1.092298
7 -0.52937787 -1.4406251 4.020928
8 -1.16771790 -0.5829220 5.188868
9 -1.16131744 -0.5856627 5.103532
10 -0.39554073 -1.5951880 4.197140
availability_365_TV number_of_reviews_ltm_TV Local_R2
1 -3.031431 0.54599195 0.05401724
2 -3.163605 0.51363567 0.05421637
3 -3.134389 0.60797580 0.05391940
4 -4.053768 0.72876564 0.01758040
5 -4.054580 0.70754905 0.01748685
6 -3.059694 0.58808391 0.05392683
7 -3.484167 0.06462904 0.14793289
8 -4.091632 0.73050690 0.01603262
9 -4.104840 0.74696731 0.01381451
10 -3.610652 0.08164529 0.15014342
geometry
1 POINT (41972.5 36390.05)
2 POINT (42051.51 36630.01)
3 POINT (42209.55 36383.43)
4 POINT (25197.84 30283.77)
5 POINT (25565.1 30085.83)
6 POINT (42074.89 36338.09)
7 POINT (28659 32635.68)
8 POINT (25427.1 30076.99)
9 POINT (25558.42 29864.68)
10 POINT (28503.19 32637.89)
gwr.adaptive.output <- as.data.frame(gwr.adaptive$SDF)
airbnb_resale.sf.adaptive <- cbind(airbnb_resale.res.sf, as.matrix(gwr.adaptive.output))glimpse(airbnb_resale.sf.adaptive)Rows: 1,781
Columns: 49
$ row_index <chr> "1", "2", "3", "4", "5", "6", "7", "…
$ id <dbl> 71609, 71896, 71903, 275343, 275344,…
$ name <chr> "Villa in Singapore · ★4.44 · 2 bedr…
$ host_id <dbl> 367042, 367042, 367042, 1439258, 143…
$ host_name <chr> "Belinda", "Belinda", "Belinda", "Ka…
$ neighbourhood_group <chr> "East Region", "East Region", "East …
$ neighbourhood <chr> "Tampines", "Tampines", "Tampines", …
$ room_type <chr> "Private room", "Private room", "Pri…
$ price <dbl> 150, 80, 80, 64, 78, 220, 85, 75, 69…
$ minimum_nights <dbl> 92, 92, 92, 60, 60, 92, 92, 60, 60, …
$ number_of_reviews <dbl> 19, 24, 46, 20, 16, 12, 131, 17, 5, …
$ last_review <chr> "17/1/20", "13/10/19", "9/1/20", "13…
$ reviews_per_month <dbl> 0.13, 0.16, 0.30, 0.15, 0.11, 0.09, …
$ calculated_host_listings_count <dbl> 5, 5, 5, 51, 51, 5, 7, 51, 51, 7, 7,…
$ availability_365 <dbl> 55, 91, 91, 183, 183, 54, 365, 183, …
$ number_of_reviews_ltm <dbl> 0, 0, 0, 0, 3, 0, 0, 1, 2, 0, 0, 0, …
$ license <chr> NA, NA, NA, "S0399", "S0399", NA, NA…
$ LOG_SELLING_PRICE <dbl> 5.010635, 4.382027, 4.382027, 4.1588…
$ MLR_RES <dbl> -111.535532, -160.703816, -147.52106…
$ Intercept <dbl> 500.2508, 551.2260, 504.1947, 381.20…
$ minimum_nights.1 <dbl> -0.5390498, -0.5849575, -0.5331751, …
$ number_of_reviews.1 <dbl> 0.009569676, 0.229994448, -0.0239319…
$ reviews_per_month.1 <dbl> -74.7018413, -103.8408323, -72.08012…
$ calculated_host_listings_count.1 <dbl> -1.44149005, -1.94279171, -1.3667687…
$ availability_365.1 <dbl> -0.9060696, -1.0346010, -0.9227310, …
$ number_of_reviews_ltm.1 <dbl> 3.0939149, 4.4876859, 3.0025573, 1.0…
$ y <dbl> 150, 80, 80, 64, 78, 220, 85, 75, 69…
$ yhat <dbl> 384.0875464, 382.4526368, 341.615308…
$ residual <dbl> -234.0875464, -302.4526368, -261.615…
$ CV_Score <dbl> 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, …
$ Stud_residual <dbl> -0.628617966, -0.811981338, -0.69893…
$ Intercept_SE <dbl> 93.67751, 105.61418, 91.15034, 39.63…
$ minimum_nights_SE <dbl> 0.5836356, 0.6871031, 0.5579039, 0.2…
$ number_of_reviews_SE <dbl> 0.8619440, 1.0777338, 0.8177892, 0.4…
$ reviews_per_month_SE <dbl> 65.89899, 94.63347, 59.16505, 19.327…
$ calculated_host_listings_count_SE <dbl> 1.2901926, 1.5450354, 1.2215577, 0.2…
$ availability_365_SE <dbl> 0.2988917, 0.3270323, 0.2943894, 0.1…
$ number_of_reviews_ltm_SE <dbl> 5.666594, 8.737099, 4.938613, 1.3930…
$ Intercept_TV <dbl> 5.3401378, 5.2192428, 5.5314627, 9.6…
$ minimum_nights_TV <dbl> -0.92360683, -0.85133875, -0.9556754…
$ number_of_reviews_TV <dbl> 0.01110243, 0.21340561, -0.02926423,…
$ reviews_per_month_TV <dbl> -1.133581019, -1.097294960, -1.21828…
$ calculated_host_listings_count_TV <dbl> -1.11726736, -1.25744152, -1.1188736…
$ availability_365_TV <dbl> -3.0314307, -3.1636052, -3.1343892, …
$ number_of_reviews_ltm_TV <dbl> 0.54599195, 0.51363567, 0.60797580, …
$ Local_R2 <dbl> 0.054017236, 0.054216374, 0.05391939…
$ coords.x1 <dbl> 41972.50, 42051.51, 42209.55, 25197.…
$ coords.x2 <dbl> 36390.05, 36630.01, 36383.43, 30283.…
$ geometry <POINT [m]> POINT (41972.5 36390.05), POIN…
summary(gwr.adaptive$SDF$yhat) Min. 1st Qu. Median Mean 3rd Qu. Max.
-145.15 99.42 174.37 198.60 267.21 3039.52
13.9.5 Visualising local R2
The code chunks below is used to create an interactive point symbol map.
tmap_mode("view")
tm_shape(mpsz_svy21)+
tm_polygons(alpha = 0.1) +
tm_shape(airbnb_resale.sf.adaptive) +
tm_dots(col = "Local_R2",
border.col = "gray60",
border.lwd = 1) +
tm_view(set.zoom.limits = c(11,14))tmap_mode("plot")13.9.6 Visualising coefficient estimates
The code chunks below is used to create an interactive point symbol map.
names(airbnb_resale.sf.adaptive) [1] "row_index" "id"
[3] "name" "host_id"
[5] "host_name" "neighbourhood_group"
[7] "neighbourhood" "room_type"
[9] "price" "minimum_nights"
[11] "number_of_reviews" "last_review"
[13] "reviews_per_month" "calculated_host_listings_count"
[15] "availability_365" "number_of_reviews_ltm"
[17] "license" "LOG_SELLING_PRICE"
[19] "MLR_RES" "Intercept"
[21] "minimum_nights.1" "number_of_reviews.1"
[23] "reviews_per_month.1" "calculated_host_listings_count.1"
[25] "availability_365.1" "number_of_reviews_ltm.1"
[27] "y" "yhat"
[29] "residual" "CV_Score"
[31] "Stud_residual" "Intercept_SE"
[33] "minimum_nights_SE" "number_of_reviews_SE"
[35] "reviews_per_month_SE" "calculated_host_listings_count_SE"
[37] "availability_365_SE" "number_of_reviews_ltm_SE"
[39] "Intercept_TV" "minimum_nights_TV"
[41] "number_of_reviews_TV" "reviews_per_month_TV"
[43] "calculated_host_listings_count_TV" "availability_365_TV"
[45] "number_of_reviews_ltm_TV" "Local_R2"
[47] "coords.x1" "coords.x2"
[49] "geometry"
sf_use_s2(TRUE)
tmap_mode("view")
number_of_reviews_SE <- tm_shape(mpsz_svy21)+
tm_polygons(alpha = 0.1) +
tm_shape(airbnb_resale.sf.adaptive) +
tm_dots(col = "number_of_reviews_SE",
border.col = "gray60",
border.lwd = 1) +
tm_view(set.zoom.limits = c(11,14))
number_of_reviews_TV <- tm_shape(mpsz_svy21)+
tm_polygons(alpha = 0.1) +
tm_shape(airbnb_resale.sf.adaptive) +
tm_dots(col = "number_of_reviews_TV",
size = 0.15,
border.col = "gray60",
border.lwd = 1, palette = "YlGn") +
tm_view(set.zoom.limits = c(11,14))
tmap_arrange(number_of_reviews_SE, number_of_reviews_TV, asp=1, ncol=2, sync = TRUE)#tm_fill/tm_borders/tm_polygons.
#Run All Chunks AboveRun Current Chunk
#number_of_reviews_TVairbnb_resale.sf.adaptive$AREA_SQM_TVNULL
names(airbnb_resale.sf.adaptive) [1] "row_index" "id"
[3] "name" "host_id"
[5] "host_name" "neighbourhood_group"
[7] "neighbourhood" "room_type"
[9] "price" "minimum_nights"
[11] "number_of_reviews" "last_review"
[13] "reviews_per_month" "calculated_host_listings_count"
[15] "availability_365" "number_of_reviews_ltm"
[17] "license" "LOG_SELLING_PRICE"
[19] "MLR_RES" "Intercept"
[21] "minimum_nights.1" "number_of_reviews.1"
[23] "reviews_per_month.1" "calculated_host_listings_count.1"
[25] "availability_365.1" "number_of_reviews_ltm.1"
[27] "y" "yhat"
[29] "residual" "CV_Score"
[31] "Stud_residual" "Intercept_SE"
[33] "minimum_nights_SE" "number_of_reviews_SE"
[35] "reviews_per_month_SE" "calculated_host_listings_count_SE"
[37] "availability_365_SE" "number_of_reviews_ltm_SE"
[39] "Intercept_TV" "minimum_nights_TV"
[41] "number_of_reviews_TV" "reviews_per_month_TV"
[43] "calculated_host_listings_count_TV" "availability_365_TV"
[45] "number_of_reviews_ltm_TV" "Local_R2"
[47] "coords.x1" "coords.x2"
[49] "geometry"
#airbnb_resale.sf.adaptive$Local_R2[:10]tm_shape(mpsz_svy21[mpsz_svy21$REGION_N=="CENTRAL REGION", ])+
tm_polygons()+
tm_shape(airbnb_resale.sf.adaptive) +
tm_bubbles(col = "Local_R2",
size = 0.15,
border.col = "gray60",
border.lwd = 1)Reflections/Personal Take
This hands on exercise was insightful in helping form a more solid understanding of what features to use for end users. As human users, it will be difficult for them to calculate spatially weighted relationships with the naked eye and this app will definitely be useful in helping them understand the relationship between price and all the various variables easily. It also makes the regression models more explainable.